/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cc.altius.dao.impl;

import cc.altius.dao.DesignationDao;
import cc.altius.model.Designation;
import java.util.List;
import javax.sql.DataSource;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

/**
 *
 * @author santosh
 */
@Repository("DesignationDao")
public class DesignationDaoImpl implements DesignationDao {

    @Autowired
    private DataSource dataSource;
    private JdbcTemplate jdbcTemplate;
    private SessionFactory sessionFactory;
    private HibernateTemplate hibernateTemplate;

    @Autowired
    public void setDataSource(DataSource dataSource) {
        this.dataSource = dataSource;
        this.jdbcTemplate = new JdbcTemplate(dataSource);
    }

    @Autowired
    public void setSessionFactory(SessionFactory sessionFactory) {
        this.sessionFactory = sessionFactory;
        this.hibernateTemplate = new HibernateTemplate(sessionFactory);
    }

    @Override
    @Transactional
    public int addDesignation(Designation designation) {

        return (Integer) this.hibernateTemplate.save(designation);
    }

    @Override
    public List<Designation> getDesignationList() {
        List<Designation> designations = this.hibernateTemplate.find("from Designation");
        return designations;
    }
}
